package org.luxor.common.netty.stream.client.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.stream.ChunkedStream;

import java.io.File;
import java.io.FileInputStream;

public class WriteStreamHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.fireChannelActive();
        // 当连接建立时，使用ChunkedInput写文件数据
        File file = new File("");
        ctx.writeAndFlush(new ChunkedStream(new FileInputStream(file)));
    }

}
